/*
 * Copyright (C) 2021 Baidu, Inc. All Rights Reserved.
 */
package com.chukun.rpc.registry;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import com.chukun.rpc.registry.lb.ZKConsistentHashLoadBalancer;

/**
 * <p>服务注册中心工厂<p/>
 *
 * @author chukun
 * @version 1.0
 * @since 1.0-SNAPSHOT
 */
public class ServiceRegistryFactory {

    private static volatile RegistryService registryService;

    public static RegistryService getInstance(String registryAddr, RegistryType type) {
        if (registryService == null) {
            synchronized(ServiceRegistryFactory.class) {
                if (registryService == null) {
                    switch (type) {
                        case ETCD:
                            registryService = new EtcdRegistryService(registryAddr);
                            break;
                        case EUREKA:
                            registryService = new EurekaRegistryService(registryAddr);
                            break;
                        case ZOOKEEPER:
                            registryService = new ZookeeperRegistryService(registryAddr);
                            break;
                    }
                }
            }
        }
        return registryService;
    }
}
